const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let n;
let initArr = [];
rl.on("line", (line) => {
    if (n === undefined) {
        n = Number(line.trim())
    } else {
        if (line.trim() === "") {
            getResult(n, initArr)
            // clear
            n === undefined
            initArr.length = 0
        }
        initArr.push(line.trim().split(" ").map(Number))
    }

})

function getResult(n, initArr) {
    // 首先统计有哪些需要依赖前置, 或者统计一个 状态
    let openStatus = new Array(n).fill(true)
    let map = {}
    for (const [a, b] of initArr) {
        openStatus[b] = false
        if (!map[a]) {
            map[a] = [b]
        } else {
            map[a].push(b)
        }
    }

    let pq = []
    for (const i in openStatus) {
        if (openStatus[i]) pq.push(i)
    }
    while (pq.length) {
        const node = pq.shift();
        openStatus[node] = true
        let arr = map[node]
        if (arr) {
            for (let index of arr) {
                pq.push(index)
            }
        }
    }
    for (const status of openStatus) {
        if (status === false) {
            console.log("no")
            return
        }
    }
    console.log("yes")
}